package com.example.myyiyanmengjava.model;

import android.util.Log;

import com.example.mvplibrary.callback.BaseModelCallback;
import com.example.mvplibrary.model.BaseModel;
import com.example.myhttplibrary.client.HttpClient;
import com.example.myyiyanmengjava.callback.HttpCallBack;
import com.example.myyiyanmengjava.callback.Mainconcations;
import com.google.gson.JsonElement;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.HashMap;

public class HomeModel<T> implements BaseModel, Mainconcations.MainModel {

    private String TAG = "朱勇闯Home";

    public void getData(final BaseModelCallback baseModelCallback, LifecycleProvider lifecycleProvider, HashMap paramser, String BaseUrl, String ApiUrl, final int type) {
        new HttpClient.Builder()
                .setBaseUrl(BaseUrl)
                .setApiUrl(ApiUrl)
                .setParamser(paramser)
                .setLifecycleProvider(lifecycleProvider)
                .post()
                .build()
                .excute(new HttpCallBack<T>() {
                    @Override
                    protected void onSuccess(T t) {
//                        Log.d(TAG, "onSuccess: " + t.toString());
                        baseModelCallback.onSuccess(t, type);
                    }

                    @Override
                    public T convert(JsonElement jsonElement) {
//                        Log.e(TAG, "convert: " + jsonElement);
                        return (T) jsonElement;
                    }

                    @Override
                    protected void error(String error, int code) {
                        Log.e(TAG, "error: " + error);
                        baseModelCallback.onError(error, code);
                    }
                });
    }
}
